package everything;

public class DumbGreedyAgent extends Agent{


	public DumbGreedyAgent(String name, String color, int x, int y, WorldMap map) {
		super(name, color, x, y, map);
		_type = "dumbGreedyAgent";
	}

	@Override
	public void makeMove() {
		int manhattanDistance = 1;
		while (_xLocation + manhattanDistance < _map.getWidth() || _xLocation - manhattanDistance >=0){
			for(int offX = 0; offX<=manhattanDistance; offX++){
				int offY = manhattanDistance - offX;
				boolean coin = (Math.random()<=0.5);
				if (_map.brickStatus(_xLocation + offX, _yLocation + offY) == WorldMap.FLAG){
					System.out.println("Greedy Agent: going to flag at (" + (_xLocation + offX)+","+(_yLocation+offY)+")." );
					if (offY==0 || (coin && offX!=0)){
						if (!_map.isMovementBlocked(_xLocation+1, _yLocation)){
							move("SOUTH");
						} else {
							setOrientation("SOUTH");
						}
					} else {
						if (!_map.isMovementBlocked(_xLocation, _yLocation+1)){
							move("EAST");
						} else {
							setOrientation("EAST");
						}

					}
					return;
				} else if (_map.brickStatus(_xLocation - offX, _yLocation + offY) == WorldMap.FLAG){
					System.out.println("Greedy Agent: going to flag at (" + (_xLocation - offX)+","+(_yLocation+offY)+")." );
					if (offY==0 || (coin && offX!=0)){
						if (!_map.isMovementBlocked(_xLocation-1, _yLocation)){
							move("NORTH");
						} else {
							setOrientation("NORTH");
						}
					} else {
						if (!_map.isMovementBlocked(_xLocation, _yLocation+1)){
							move("EAST");
						} else {
							setOrientation("EAST");
						}
					}
					return;
				} else if (_map.brickStatus(_xLocation + offX, _yLocation - offY) == WorldMap.FLAG){
					System.out.println("Greedy Agent: going to flag at (" + (_xLocation + offX)+","+(_yLocation - offY)+")." );
					if (offY==0 || (coin && offX!=0)){
						if (!_map.isMovementBlocked(_xLocation+1, _yLocation)){
							move("SOUTH");
						} else {
							setOrientation("SOUTH");
						}
					} else {
						if (!_map.isMovementBlocked(_xLocation, _yLocation-1)){
							move("WEST");
						} else {
							setOrientation("WEST");
						}

					}
					return;
				} else if (_map.brickStatus(_xLocation - offX, _yLocation - offY) == WorldMap.FLAG){
					System.out.println("Greedy Agent: going to flag at (" + (_xLocation - offX)+","+(_yLocation - offY)+")." );
					if (offY==0 || (coin && offX!=0)){
						if (!_map.isMovementBlocked(_xLocation-1, _yLocation)){
							move("NORTH");
						} else {
							setOrientation("NORTH");
						}
					} else {
						if (!_map.isMovementBlocked(_xLocation, _yLocation-1)){
							move("WEST");
						} else {
							setOrientation("WEST");
						}

					}
					return;
				}
			}
			manhattanDistance++;
		}
		System.out.println("GreedyAgent: No Flags");
	}

	@Override
	public boolean isKilling(int x, int y, WorldMap map) {
		return false;
	}

}
